package cn.tedu.boot22.controller;

import cn.tedu.boot22.entity.Hero;
import cn.tedu.boot22.mapper.HeroMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HeroController {
    // 此注解的作用: Spring 框架结合 Mybatis 框架会自动将 HeroMapper 生成一个实现类和
    //实现里面的方法 而且会自动实例化该对象   required = false 告诉 idea 编译器此对象是非必须的.
    @Autowired
    HeroMapper mapper;

    @RequestMapping("/add")
    @ResponseBody
    public String add(Hero hero){
        mapper.insert(hero);
        System.out.println("hero = " + hero);
        return "添加完成";
    }

}
